//Class that represents ressources

Ressource = function(){
	//1st index is library index, second index img index
	var tileImg;//Array[class index instance]
	var overTileImg;
	var monsterImg;
	var buildingImg;
	
	var mapArray;
	//AMapArray=[[[[1,3],...],...],...] 
	//1 : library number, 3 index number, next array : cell array, next array : y array, next array : x array.
	
	//getterAndSetter
	Ressource.prototype.setTileImg = function(aTileImg){
			tileImg = aTileImg;
	}
	Ressource.prototype.getTileImg = function(){
			return tileImg;
	}
	
	Ressource.prototype.setOverTileImg = function(anOverTileImg){
			overTileImg = anOverTileImg;
	}
	Ressource.prototype.getOverTileImg = function(){
			return overTileImg;
	}
	
	Ressource.prototype.setMonsterImg = function(aMonsterImg){
			monsterImg = aMonsterImg;
	}
	Ressource.prototype.getMonsterImg = function(){
			return monsterImg;
	}
	
	Ressource.prototype.setBuildingImg = function(aBuildingImg){
			buildingImg = aBuildingImg;
	}
	Ressource.prototype.getBuildingImg = function(){
			return buildingImg;
	}
	
	Ressource.prototype.setMapArray = function(aMapArray){
			mapArray = aMapArray;
	}
	Ressource.prototype.getMapArray = function(){
			return mapArray;
	}
}

//constructor
Ressource.prototype.initialize = function(backgroundLibraries,monsterLibraries,someMapIndex){

		this.setTileImg(new Array());
		this.setOverTileImg(new Array());
		this.setMonsterImg(new Array());
		this.setBuildingImg(new Array());
		
		this.loadImg(backgroundLibraries,monsterLibraries);//load 
		this.loadMap(someMapIndex);//load mapArray from XML
}

Ressource.prototype.loadMap = function(someMapIndex){
	//TO DO
	/*********************************************/
	this.setMapArray([[[[1,1]],[[1,2]]],[[[1,3]],[[1,4]]]]);
	/***********************************************/
}

//load images from URL
Ressource.prototype.loadImg = function(backgroundLibraries,monsterLibraries){
	/*function that permits to load images : later it should be divided in several script and
	be loaded asynchronously through the library requireJS*/
	/*arguments are not used yet*/
	
	//URL for loading images. -> To stock in a xml please...
	var tileDict = Array("","road.png","grass.png","dirt.png","savanna.png");
	var tileOverDict = Array("","road-ne-se.png","road-sw-nw.png","road-n-ne.png","road-s-sw.png","road-test.png","road-ne.png","savanna-s-sw-nw.png","savanna-sw.png","savanna-s-sw.png","savanna-s.png");
	var monsterDict = Array("","whiteMage.png","thief.png","paladin.png","specter.png","shyde.png");
	var buildingDict = Array("","house.png");
	
	//load test -> TO DO change as it was before with a class loading bar that can de displayed...
	var loaded = 0;
	var totalToLoad = tileDict.length + tileOverDict.length + monsterDict.length + buildingDict.length - 4;
	
	//loading tiles
	this.loadDictionnary(tileDict, this.getTileImg(), "tiles", loaded, totalToLoad);
	//loading tiles over
	this.loadDictionnary(tileOverDict, this.getOverTileImg(), "overtiles", loaded, totalToLoad);
	//loading monsters
	this.loadDictionnary(monsterDict, this.getMonsterImg(), "monsters", loaded, totalToLoad);
	//loading buildings
	this.loadDictionnary(buildingDict, this.getBuildingImg(), "buildings", loaded, totalToLoad);
}

Ressource.prototype.loadDictionnary = function(dict, arrayImg, path, loaded, totalToLoad){
	for(var i=1;i<dict.length;i++){
		arrayImg[i] = new Image();
		arrayImg[i].src = "../../ressources/images/" + path + "/" + dict[i];
		arrayImg[i].onload = function(){
			loaded++;
			if (loaded === totalToLoad){
				//TO DO world.follow initialisation.
			}
		}
	}
}